package com.example.myschool;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class WelcomeActivity extends AppCompatActivity {
    private TextView tvCountdown;
    private CountDownTimer countDownTimer;
    private long timeLeftInMillis = 4000;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        tvCountdown =findViewById(R.id.tv_countdown);
        startCountdown();

    }

    private void startCountdown() {
        countDownTimer = new CountDownTimer(timeLeftInMillis,1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                timeLeftInMillis = millisUntilFinished;
                int secondsRemaining =(int) (millisUntilFinished / 1000);
                tvCountdown.setText(secondsRemaining +" s");
            }

            @Override
            public void onFinish(){
                //跳转对应页面，跳转到登陆页面
                startActivity(new Intent(WelcomeActivity.this,LoginActivity.class));
                finish();
            }
        }.start();
    }
    @Override
    protected void onDestroy(){
        super.onDestroy();
        if (countDownTimer !=null){
            countDownTimer.cancel();
        }
    }
}